﻿//-----------------------------------------------------------------------------
// <copyright file="MainWindowViewModelTests.cs" company="William E. Kempf">
//     Copyright (c) William E. Kempf.
// </copyright>
//-----------------------------------------------------------------------------

namespace SimpleTest
{
    using System.Windows;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using Onyx.Windows;
    using Simple;
    using SimpleTest.TestArtifacts;
    using Testing.Specificity;

    /// <summary>
    /// Provides tests for the <see cref="MainWindowViewModel"/> class.
    /// </summary>
    [TestClass]
    public class MainWindowViewModelTests
    {
        /// <summary>
        /// Verifies that the constructor does not throw.
        /// </summary>
        [TestMethod]
        public void Constructor_GivenView_ShouldNotThrow()
        {
            Specify.ThatAction(delegate
            {
                var element = new DependencyObject();
                View view = View.GetView(element);
                var presenter = new MainWindowViewModel(view);
            }).ShouldNotHaveThrown();
        }

        /// <summary>
        /// Verifies that <see cref="MainWindowPresenter.TestMessageDisplay"/> displays a message when
        /// executed.
        /// </summary>
        [TestMethod]
        public void TestMessageDisplayCommand_WhenExecuted_ShouldDisplayMessage()
        {
            var message = "xyzzy";
            string actualMessage = null;
            var element = new TestableViewElement();

            var fakeDisplayMessage = new FakeDisplayMessage();
            fakeDisplayMessage.ShowMessage = (text, caption, button, icon, result, options) =>
            {
                actualMessage = text;
                return MessageBoxResult.OK;
            };
            element.AddService(typeof(IDisplayMessage), fakeDisplayMessage);

            var fakeTestMessage = new FakeTestMessage();
            fakeTestMessage.GetTestMessage = () => message;
            element.AddService(typeof(ITestMessage), fakeTestMessage);

            View view = View.GetView(element);
            var presenter = new MainWindowViewModel(view);
            MainWindowViewModel.TestMessageDisplay.Execute(null, element);
            Specify.That(actualMessage).ShouldBeEqualTo(message);
        }
    }
}
